# -*- coding: utf-8 -*-
# @Date   : 2020/3/19
# @File   : R04_EG_IndLimitCheck_CF.py
# @Author : zhaochen
# -*- coding: utf-8 -*-

'''eof
name:行业限制校验
code:R04_EG_IndLimitCheck
tableName:
columnName:
groups:企业业务信息校验
dependencies:CQB_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''


import sys
import json
reload(sys)
sys.setdefaultencoding('utf-8')



def FormatData(tableName):
    try:
        ic = CQB_DSJ.get("data").get(tableName)
        return ic if isinstance(ic, list) else [{}]
    except:
        return [{}]


def is_num(num):
    try:
        float(num)
        return True
    except:
        return False


def getRule04():
    null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']
    try:
        depositInfo = FormatData("industryInfo")
        if depositInfo == [{}]:
            raise RuntimeError("未能获取到行业信息")
        else:
            if len(depositInfo) >= 1:
                for i in depositInfo:
                    deposit = i.get("isInTransit")
                    if deposit not in null_type_list and deposit == u"Y":
                        return 0
                    elif deposit not in null_type_list and deposit == u"N":
                        return 1
                    else:
                        raise ValueError("行业信息准入信息格式错误;deposit = " + deposit)
            else:
                raise RuntimeError("行业信息为空")
    except:
        raise


if __name__ == "__main__":
    file_obj = open(r'../data/rating/R04_EG_IndLimitCheck/CQB_DSJ.json', 'r')
    content = file_obj.read()
    CQB_DSJ = json.loads(content, strict=False)
    aa = getRule04()
    print aa

result = getRule04()

